package com.wsd.smartcarwasher.dao;

import com.wsd.smartcarwasher.domain.OrderInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.shiro.dao.DataAccessException;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface OrderDao {

    List<String> getAllOrderSn() throws DataAccessException;

    int addOrderInfo(OrderInfo order) throws DataAccessException;

    OrderInfo queryOrderInfoByOrderSn(@Param("orderSn") String orderSn) throws DataAccessException;

    int updateOrderPayPrice(@Param("orderSn") String orderSn, @Param("payPrice")BigDecimal payPrice);

    OrderInfo queryOrderByOrderSn(@Param("orderSn") String orderSn) throws DataAccessException;

    int deleteOrderInfo(@Param("orderSn") String orderSn) throws DataAccessException;

    int updateOrderInfo(OrderInfo orderInfo) throws DataAccessException;

    OrderInfo queryUnPaidOrder(@Param("userId") String userId) throws DataAccessException;

    int changeOrderConsumed(String orderSn) throws DataAccessException;

    List<OrderInfo> queryAllOrdersByCondition(@Param("filterCondition")Map<String,Object> filterCondition);



    List<OrderInfo> queryAllOrdersByCashWithdrawal();
//查询当前时间最近的一条记录

    Map<String,Object> queryByLatelyUserId(String userId);

    int cashWithdrawalSuccess(@Param("list") List<OrderInfo> list);

    int cashWithdrawalFail(@Param("list") List<OrderInfo> list);
    @Update("update t_order set payNode=#{days} where orderSn=#{orderSn}")
    int updatePayNode(String orderSn,Integer days);

    @Update("update t_order set endTime=NOW() where orderSn=#{orderSn}")
    int createUnEndTimeOrder(String orderSn);

    @Select("select  * from t_order where payStatus=2 and consumed=1 and endTime is null  and prorateStatus=1 order by createTime desc limit 0,100")
    List<OrderInfo> queryUnEndTimeOrder();

    List<OrderInfo> queryOrderInfoByMachineIds(@Param("machineIds") List<Integer> machineIds,
                                               @Param("partnerId") Integer partnerId) throws DataAccessException;

    List<OrderInfo> queryOrderInfoByMachineIdsByRu(@Param("machineIds") List<Integer> machineIds,@Param("partnerId") Integer id);

    /**
     * 查询订单信息
     * @param machineId 如果机器id为空，则查询所有订单信息
     * @return
     * @throws DataAccessException
     */
    List<OrderInfo> queryOrderInfoByMachineId(@Param("machineId") String machineId,
                                              @Param("partnerId") Integer partnerId) throws DataAccessException;

    List<OrderInfo> queryUserOrder(String userId,Integer machineId) throws DataAccessException;

    int saveOrderCarWashPhoto(OrderInfo orderInfo);

    OrderInfo queryCardIsActivityAndUsed(@Param("userId") String userId,@Param("ucId") String ucId);

    OrderInfo queryCreatedOrder(@Param("userId") String userId);
}
